#include "tick.h"
#include "stm32f10x.h"
#include "core_cm3.h"

static volatile unsigned long long systme_count_ms = 0;

int tick_init(void) {
	unsigned int SystemFrequency = 72000000;
// SystemFrequency / 1000    1ms
// SystemFrequency / 100000  10us
// SystemFrequency / 1000000 1us
	systme_count_ms = 0;
	if (SysTick_Config(SystemFrequency / 1000)) { 
		return -1;
    }
	return 0;
}

void delay_ms(unsigned int ms) {
	unsigned int tick_count = systme_count_ms + ms;
	
	while(tick_count > get_tick_count());
}

unsigned int get_tick_count() {
	return systme_count_ms;
}

void tick_plus(void) {
	systme_count_ms ++;
}
